<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class Tools_HelpVideoObject extends Erra_Fields_Base_Object {

    public static function displayHelpVideo($licence_object) {
        $res  = '<script type="text/javascript">';
        $res .= '   $(document).ready(function() {';
        $res .= '       $("#panel2").slidePanel({';
        $res .= '           triggerName: "#trigger2",';
        $res .= '           triggerTopPos: "0px",';
        $res .= '           panelTopPos: "0px"';
        $res .= '       });';
        $res .= '   });';
        $res .= '</script>';

        $res .= '<a href="#" id="trigger2" class="trigger right">Vidéo d\'aide</a>';
        $res .= '<div id="panel2" class="panel right">';

        // Display video if possible
        $videoContent = '';
        foreach ($licence_object->videos as $video) {
            $pageName = Erra_System_PageBuilder::getCurrentPageName();
            $pageName = strstr($pageName, '/') ? strstr($pageName, '/', true) : $pageName;
            if ($video->url == $pageName) {
                if (strlen($video->youtube_video) && strstr($video->youtube_video, 'http://youtu.be/')) {
                    $videoContent .= '<p>' . $video->help_text . '</p>';
                    $fragment = str_replace('http://youtu.be/', '', $video->youtube_video);
                    $videoContent .= '<iframe width="560" height="315" src="http://www.youtube.com/embed/' . $fragment . '" frameborder="0" allowfullscreen>';
                    $videoContent .= '</iframe>';
                }
            }
        }
        if (!strlen($videoContent)) {
            $videoContent = "<p>Aucune vidéo d'aide disponible</p>";
        }
        $res .= $videoContent;
        $res .=' </div>';
        return $res;
    }

}

?>
